# Making the + operator handle different cases
import string
from types import *
# definitions -----------------------
class BasketEggs:

    def __init__(self):
        self.eggs = 1 #Basket starts with one egg

    def __coerce__(self, other):
        print "coerce method"
        aBasketEggs = BasketEggs()
        if type( other ) == type( aBasketEggs ): #BasketEggs type
            return (self, other)

        elif type( other ) == type( "" ): #String type
            'Convert string s to an integer in the given base.'
            eggs = int( other )
            aBasketEggs.eggs = eggs
            return (self, aBasketEggs)

        elif type( other ) == type ( 0 ): #Integer type
            aBasketEggs.eggs = other
            return (self, aBasketEggs)

        elif type( other ) == ListType: #List type
            eggsCount = 0
            for i in other:
                eggsCount += i
            aBasketEggs.eggs = eggsCount
            return (self, aBasketEggs)
        else:
            return None
        
    def __add__(self, other):
        print "add method"
        aBasketEggs = BasketEggs()
        aBasketEggs.eggs = self.eggs + other.eggs
        return aBasketEggs

# implementations -----------------------    
a = BasketEggs()
b = BasketEggs()
a = a + b
print "a now has ", a.eggs, " eggs"
a = a + "25"
print "a now has ", a.eggs, " eggs"
a = a + 2
print "a now has ", a.eggs, " eggs"
a = a + [1,2,3]
print "a now has ", a.eggs, " eggs"
